package com.orangelife.mobile.propertyOld.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.curry.android.adapter.FatherAdapter;
import com.curry.orangelife.mobile.R;
import com.orangelife.mobile.widget.ScrollListView;

import java.util.List;
import java.util.Map;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * 物业缴费的小区对应的缴费项
 * Created by ${shz} on 2015/12/3.
 */
public class PropertyBillListOldAdapter<T> extends FatherAdapter<T> {

    private Context mContext;
    private List<T> mList;
    private PropertyBillListOldChildAdapter mAdapter;

    public PropertyBillListOldAdapter(Context context, List<T> list) {
        this.mContext = context;
        this.mList = list;
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public Object getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public BaseAdapter setList(List<T> list) {
        if (mList != null && list != null) {
            mList.clear();
            mList.addAll(list);
        }
        return PropertyBillListOldAdapter.this;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_lv_property_cost_new, null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        Map<String, Object> map = (Map<String, Object>) mList.get(position);
        String mComm = String.valueOf(map.get("comm"));
        String mPmfeeTime = String.valueOf(map.get("pmfeeTime"));
        String commID=String.valueOf(map.get("commID"));
        List<Map<String, Object>> mList = (List<Map<String, Object>>) map.get("orderInfo");
        if (mList != null && mList.size() != 0) {
            mAdapter = new PropertyBillListOldChildAdapter(mContext, mList,commID);
            viewHolder.lvChildren.setAdapter(mAdapter);
        }
        viewHolder.tvCommunity.setText(mComm);
        viewHolder.tvDate.setText(mPmfeeTime);
        return convertView;
    }

    static class ViewHolder {
        @Bind(R.id.ivCheck)
        ImageView ivCheck;
        @Bind(R.id.tvCommunity)
        TextView tvCommunity;
        @Bind(R.id.llCommunity)
        LinearLayout llCommunity;
        @Bind(R.id.tvTime)
        TextView tvTime;
        @Bind(R.id.tvDate)
        TextView tvDate;
        @Bind(R.id.lvChildren)
        ScrollListView lvChildren;
        @Bind(R.id.rlItem)
        LinearLayout rlItem;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
